package com.lcf.trans.test01.service.impl;

import com.lcf.trans.entity.User;
import com.lcf.trans.test01.mapper.UserMapper;
import com.lcf.trans.test01.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.UUID;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User queryUserById(String id) {
        User user = userMapper.queryUserById(id);
        return user;
    }

    /**
     * 配置了多数据源，需要指定事务管理器
     * @param name
     * @param age
     * @return
     */
    @Override
    @Transactional
    public Integer insertUser(String name, int age) {
        String id = UUID.randomUUID().toString().replace("-", "");
        Integer integer = userMapper.insertUser(id, name, age);
        int i = 1 / age;
        log.info("插入user");
        return integer;
    }
}
